unit fMain;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Menus, StdCtrls, oFormConfig, oScene,
  oMasterManager, ComCtrls, ImgList, Generics.Collections,
  Main, oFormSimulation, oSimulation, oStatisticProcessor,
  oFormDocasneVykreslovanieNaGrid, oCellularMotion, ToolWin, ActnMan, ActnCtrls,
  StdActns, ActnList, PlatformDefaultStyleActnCtrls, ActnPopup; // docasne pridal styfi

type
  TfrmMain = class(TForm)
    mnuMenu: TMainMenu;
    mitProjet: TMenuItem;
    mitNewProject: TMenuItem;
    mitOpenProject: TMenuItem;
    mitClose: TMenuItem;
    mitInsert: TMenuItem;
    mitLogicalEntity: TMenuItem;
    mitPhysicalEntity: TMenuItem;
    mitPath: TMenuItem;
    mitPedestrians: TMenuItem;
    mitArrivals: TMenuItem;
    mitProperties: TMenuItem;
    mitRunProperties: TMenuItem;
    mitConfiguration: TMenuItem;
    mitStatistics: TMenuItem;
    mitView: TMenuItem;
    mitExport: TMenuItem;
    mitImport: TMenuItem;
    mitLanguage: TMenuItem;
    mitEnglish: TMenuItem;
    mitSlovak: TMenuItem;
    Exit: TMenuItem;
    treProject: TTreeView;
    popTreeMenu: TPopupMenu;
    iltTreeImage: TImageList;
    del1: TMenuItem;
    RunProperties1: TMenuItem;
    mitSimulation: TMenuItem;
    mitRun: TMenuItem;
    SaveConfig1: TMenuItem;
    Path1: TMenuItem;
    Pedestrian1: TMenuItem;
    ArrivalsGroup1: TMenuItem;
    N1: TMenuItem;
    db1: TMenuItem;
    db2: TMenuItem;
    db3: TMenuItem;
    N2: TMenuItem;
    mitCompute: TMenuItem;
    add1: TMenuItem;
    Button2: TButton;
    ActionManager: TActionManager;
    ImageListActions: TImageList;
    ProjectOpen: TFileOpen;
    ProjectExit: TFileExit;
    ActionToolBarProject: TActionToolBar;
    ProjectNew: TFileOpen;
    ProjectClose: TAction;
    SaveConfig: TAction;
    ActionToolBar1: TActionToolBar;
    InsertPL: TAction;
    InsertLL: TAction;
    InsertPathsGroup: TAction;
    InsertPath: TAction;
    InsertPedestriansGroup: TAction;
    InsertPedestrian: TAction;
    InsertArrivalsGroup: TAction;
    InsertArrival: TAction;
    InsertRunProperties: TAction;
    SimulationRun: TAction;
    StatisticsCompute: TAction;
    StatisticsView: TAction;
    StatisticsExport: TFileSaveAs;
    StatisticsImport: TFileOpen;
    Button3: TButton;
    RemoveSelectedLayer: TAction;
    Button1: TButton;
    procedure btnTestClick(Sender: TObject);
    procedure ExitClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure treProjectClick(Sender: TObject);
    procedure treProjectContextPopup(Sender: TObject; MousePos: TPoint;
      var Handled: Boolean);
    procedure menuDelClick(Sender: TObject);
    procedure Editor1Click(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure btnTestGeneratorClick(Sender: TObject);
    procedure SaveConfig1Click(Sender: TObject);
    procedure menuInsertClick(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure ProjectOpenAccept(Sender: TObject);
    procedure ProjectNewAccept(Sender: TObject);
    procedure ProjectCloseExecute(Sender: TObject);
    procedure SaveConfigExecute(Sender: TObject);
    procedure InsertPLExecute(Sender: TObject);
    procedure InsertLLExecute(Sender: TObject);
    procedure InsertPathsGroupExecute(Sender: TObject);
    procedure InsertPathExecute(Sender: TObject);
    procedure InsertPedestriansGroupExecute(Sender: TObject);
    procedure InsertPedestrianExecute(Sender: TObject);
    procedure InsertArrivalsGroupExecute(Sender: TObject);
    procedure InsertArrivalExecute(Sender: TObject);
    procedure InsertRunPropertiesExecute(Sender: TObject);
    procedure SimulationRunExecute(Sender: TObject);
    procedure StatisticsComputeExecute(Sender: TObject);
    procedure StatisticsViewExecute(Sender: TObject);
    procedure StatisticsExportAccept(Sender: TObject);
    procedure StatisticsImportAccept(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure treProjectDblClick(Sender: TObject);
    procedure RemoveSelectedLayerExecute(Sender: TObject);
  private
    aMaster: TMasterManager;
    aSimulation: TPedSimulation;
    aFormSimulation: tFormSimulation;
    { Private declarations }
  public
    { Public declarations }
    property Master: TMasterManager read aMaster write aMaster;
    property Simulation: TPedSimulation read aSimulation write aSimulation;
  end;

var
  frmMain: TfrmMain;
  frmEditor: TMainForm;

implementation

uses
   obstacle, oLevel, oSink, oSpawn, oCoordinates, oPedestrian, //fGenerator,
   oEntityTypeConstants, oPolygon, oProcessItem, oProcessObjectConstants, oProcessObjects,
   oRunPropertiesManager;

resourcestring
  sYouMustCheckFI = 'Najprv musite zaskrtnut fyzicku vrstvu';

{$R *.dfm}

procedure TfrmMain.treProjectClick(Sender: TObject);
var
  P: TPoint;
  node: TTreeNode;
begin
  GetCursorPos(P);
  P := treProject.ScreenToClient(P);
  node := TTreeview(sender).GetNodeAt(P.X, P.Y) ;
  frmMain.RemoveSelectedLayer.Enabled := False;
  if Assigned(node) and (node = treProject.Selected) then
    aMaster.ProcessObject(TProcessItem.create(PO_TREE_LEFT_CLICK, nil))
  else
    TTreeview(sender).ClearSelection();
end;

procedure TfrmMain.treProjectContextPopup(Sender: TObject; MousePos: TPoint;
  var Handled: Boolean);
var
  treeView : TTreeView;
  node : TTreeNode;
  ret : TProcessItem;
begin
  treeView := TTreeview(sender) ;
  node := treeView.GetNodeAt(MousePos.X, MousePos.Y) ;
  if Assigned(node) then
  begin
    TreeView.Selected := node;
    ret := aMaster.ProcessObject(TProcessItem.create(PO_TREE_RIGHT_CLICK, nil));
    if (ret.Code = PO_SUCCESS) then
      Handled := False
    else
      Handled := True;
  end;

end;

procedure TfrmMain.treProjectDblClick(Sender: TObject);
var
  P: TPoint;
  node: TTreeNode;
begin
  GetCursorPos(P);
  P := treProject.ScreenToClient(P);
  node := TTreeview(sender).GetNodeAt(P.X, P.Y) ;
  if Assigned(node) and (node = treProject.Selected) then
  aMaster.ProcessObject(TProcessItem.create(PO_TREE_LEFT_DOUBLE_CLICK, nil));
end;

procedure TfrmMain.menuDelClick(Sender: TObject);
begin
  aMaster.ProcessObject(TProcessItem.create(PO_TREE_MENU_DEL_CLICK, nil));
end;

procedure TfrmMain.SaveConfig1Click(Sender: TObject);
var
  frm: TfrmConfig;
  data : TConfignData;
begin
  frm := TfrmConfig.Create(nil);

  if frm.ShowModal = 1 then
  begin
    data := (aMaster.ProcessObject(TProcessItem.create(PO_TREE_GET_CHECKED, NIL)).Data AS TConfignData);
    data.Name := frm.getName;
    aMaster.ProcessObject(TProcessItem.create(PO_CONFIG_INSERT, Data));
    aMaster.ProcessObject(TProcessItem.create(PO_TREE_INSERT_CONFIG_LAYER, TString.Create(frm.getName)));
  end;

  frm.Free;
end;

procedure TfrmMain.SaveConfigExecute(Sender: TObject);
var
  frm: TfrmConfig;
  data : TConfignData;
begin
  frm := TfrmConfig.Create(nil);

  if frm.ShowModal = 1 then
  begin
    data := (aMaster.ProcessObject(TProcessItem.create(PO_TREE_GET_CHECKED, NIL)).Data AS TConfignData);
    data.Name := frm.getName;
    aMaster.ProcessObject(TProcessItem.create(PO_CONFIG_INSERT, Data));
    aMaster.ProcessObject(TProcessItem.create(PO_TREE_INSERT_CONFIG_LAYER, TString.Create(frm.getName)));
  end;

  frm.Free;
end;

procedure TfrmMain.SimulationRunExecute(Sender: TObject);
var
  list : TProcessingList;
begin
  TStatisticProcessor.SimulationId := aMaster.ProjectManager.Project.SimulationId;
  aMaster.ProjectManager.Project.SimulationId :=
  aMaster.ProjectManager.Project.SimulationId + 1;
  aMaster.ProcessObject(TProcessItem.create(PO_PROJECT_SAVE_WITH_PATH, NIL));

  list := TProcessingList.Create;
  list.addParameter(TString.Create(aMaster.ProjectManager.Project.Path + '\stats'));
  list.addParameter(TProcessingForm.Create(self));
  aMaster.ProcessObject(TProcessItem.create(PO_SIM_RENDERER_SHOW, list));
end;

procedure TfrmMain.StatisticsComputeExecute(Sender: TObject);
begin
  aMaster.ProcessObject(TProcessItem.create(PO_EDITOR_STAT_COMPUTE, nil));
  StatisticsView.Enabled := True;
  StatisticsExport.Enabled := True;
end;

procedure TfrmMain.StatisticsExportAccept(Sender: TObject);
begin
  aMaster.ProcessObject(TProcessItem.create(PO_EDITOR_STAT_SAVE,
    TString.Create(StatisticsExport.Dialog.FileName)));
end;

procedure TfrmMain.StatisticsImportAccept(Sender: TObject);
begin
  StatisticsExport.Enabled := true;
  aMaster.ProcessObject(TProcessItem.create(PO_EDITOR_STAT_LOAD,
    TString.Create(StatisticsImport.Dialog.FileName)));
end;

procedure TfrmMain.StatisticsViewExecute(Sender: TObject);
begin
  aMaster.ProcessObject(TProcessItem.create(PO_EDITOR_STAT_SHOW, nil));
end;

procedure TfrmMain.menuInsertClick(Sender: TObject);
begin
  aMaster.ProcessObject(TProcessItem.create(PO_TREE_MENU_INSERT_CLICK, nil));
end;

procedure TfrmMain.btnTestClick(Sender: TObject);
var
  s: string;
  a, b: TList<TString>;
  p, d: TString;
      list : tList;
      polygon : tPolygon;
      level: TLevel;
begin
   level := (aMaster.ProcessObject(TProcessItem.create(PO_SCENE_GET_LEVEL, nil)).Data AS TprocessingLEvel).Level;
      // teraz sink
      list := tList.Create;
      list.Add(TCoordinates.Create(160 , 20));
      list.Add(TCoordinates.Create(180 , 20));
      list.Add(TCoordinates.Create(180 , 40));
      list.Add(TCoordinates.Create(160 , 40));
      polygon := Tpolygon.Create(list,100);
      level.insertLogicalEntity(100,ET_SINK_TYPE,polygon,0);

      list := tList.Create;
      list.Add(TCoordinates.Create(160 , 50));
      list.Add(TCoordinates.Create(180 , 50));
      list.Add(TCoordinates.Create(180 , 60));
      list.Add(TCoordinates.Create(160 , 60));
      polygon := Tpolygon.Create(list,101);
      level.insertLogicalEntity(101,ET_SPAWN_TYPE,polygon,0);

      list := tList.Create;
      list.Add(TCoordinates.Create(160 , 70));
      list.Add(TCoordinates.Create(180 , 70));
      list.Add(TCoordinates.Create(180 , 80));
      list.Add(TCoordinates.Create(160 , 80));
      polygon := Tpolygon.Create(list,102);
      level.insertLogicalEntity(102,ET_TURNIQUET_TYPE,polygon,0);

      list := tList.Create;
      list.Add(TCoordinates.Create(160 , 90));
      list.Add(TCoordinates.Create(180 , 90));
      list.Add(TCoordinates.Create(180 , 100));
      list.Add(TCoordinates.Create(160 , 100));
      polygon := Tpolygon.Create(list,103);
      level.insertLogicalEntity(103,ET_TURNIQUET_TYPE,polygon,0);

 { s := 'Project name';
  aMaster.ProcessObject(TProcessItem.create(PO_TREE_SHOW_PROJECT, TString.Create(s)));

  s := 'FI1';
  aMaster.ProcessObject(TProcessItem.create(PO_TREE_INSERT_PHYS_LAYER_FAST, TString.Create(s)));
  s := 'FI2';
  aMaster.ProcessObject(TProcessItem.create(PO_TREE_INSERT_PHYS_LAYER_FAST, TString.Create(s)));
  s := 'FI3';
  aMaster.ProcessObject(TProcessItem.create(PO_TREE_INSERT_PHYS_LAYER_FAST, TString.Create(s)));
  s := 'FI4';
  aMaster.ProcessObject(TProcessItem.create(PO_TREE_INSERT_PHYS_LAYER_FAST, TString.Create(s)));
  s := 'LI1';
  aMaster.ProcessObject(TProcessItem.create(PO_TREE_INSERT_LOG_LAYER_FAST, TString.Create(s)));
  s := 'LI2';
  aMaster.ProcessObject(TProcessItem.create(PO_TREE_INSERT_LOG_LAYER_FAST, TString.Create(s)));
  s := 'LI3';
  aMaster.ProcessObject(TProcessItem.create(PO_TREE_INSERT_LOG_LAYER_FAST, TString.Create(s)));
  s := 'cI1';
  aMaster.ProcessObject(TProcessItem.create(PO_TREE_INSERT_PATHS_LAYER_FAST, TString.Create(s)));

  s := 'ak';
  a := TList<TString>.Create();
  b := TList<TString>.Create();
  p := TString.Create(s);
  s := 'pp';
  d := TString.Create(s);
  a.Add(p);
  a.Insert(0, d);
  b.Add(p);
//  a.Free;
  ShowMessage(a[1].String_);
  b.Free;}

end;

procedure TfrmMain.btnTestGeneratorClick(Sender: TObject);
{var
  frm: TfrmGenerator; }
begin
  {frm := TfrmGenerator.Create(nil);
  frm.Show;
  frm.Free;}
end;

procedure TfrmMain.Button1Click(Sender: TObject);
begin
  if Svet = nil then Svet := tLevel.Create(350, 350);
  Docasny.ShowWorld(Svet);
end;

procedure TfrmMain.Button2Click(Sender: TObject);
var
  list : TProcessingList;
  j : integer;
  item : TProcessItem;

begin
  list := TProcessingList.Create;
  list.addParameter(TString.Create('cesta1'));
  item := aMaster.ProcessObject(TProcessItem.create(PO_SCENE_GET_ENTITY_BY_ID,
    TInteger.Create(1)));
  list.addParameter(TEntityProcessing.Create((item.Data as TEntityProcessing).Entity_));
  list.addParameter(nil);
  aMaster.ProcessObject(TProcessItem.create(PO_PATHS_INSERT_WAYPOINT, list));

  list := TProcessingList.Create;
  list.addParameter(TString.Create('cesta1'));
  item := aMaster.ProcessObject(TProcessItem.create(PO_SCENE_GET_ENTITY_BY_ID,
    TInteger.Create(0)));
  list.addParameter(TEntityProcessing.Create((item.Data as TEntityProcessing).Entity_));
  item := aMaster.ProcessObject(TProcessItem.create(PO_SCENE_GET_ENTITY_BY_ID,
    TInteger.Create(1)));
  list.addParameter(TEntityProcessing.Create((item.Data as TEntityProcessing).Entity_));
  aMaster.ProcessObject(TProcessItem.create(PO_PATHS_INSERT_WAYPOINT, list));
  aMaster.ProcessObject(TProcessItem.create(PO_PROJECT_SAVE_PATHS, NIL));

end;

procedure TfrmMain.Button3Click(Sender: TObject);
var
  list : TProcessingList;
  j : integer;
  item : TProcessItem;

begin
  list := TProcessingList.Create;
  list.addParameter(TString.Create('cesta'));
  item := aMaster.ProcessObject(TProcessItem.create(PO_SCENE_GET_ENTITY_BY_ID,
    TInteger.Create(2)));
  list.addParameter(TEntityProcessing.Create((item.Data as TEntityProcessing).Entity_));
  list.addParameter(nil);
  aMaster.ProcessObject(TProcessItem.create(PO_PATHS_INSERT_WAYPOINT, list));

  list := TProcessingList.Create;
  list.addParameter(TString.Create('cesta'));
  item := aMaster.ProcessObject(TProcessItem.create(PO_SCENE_GET_ENTITY_BY_ID,
    TInteger.Create(2)));
  list.addParameter(TEntityProcessing.Create((item.Data as TEntityProcessing).Entity_));
  item := aMaster.ProcessObject(TProcessItem.create(PO_SCENE_GET_ENTITY_BY_ID,
    TInteger.Create(3)));
  list.addParameter(TEntityProcessing.Create((item.Data as TEntityProcessing).Entity_));
  aMaster.ProcessObject(TProcessItem.create(PO_PATHS_INSERT_WAYPOINT, list));
  aMaster.ProcessObject(TProcessItem.create(PO_PROJECT_SAVE_PATHS, NIL));
end;

procedure TfrmMain.ProjectCloseExecute(Sender: TObject);
begin
  aMaster.ProcessObject(TProcessItem.create(PO_SCENE_UNLOAD_LOG_LAYER, NIL));
  aMaster.ProcessObject(TProcessItem.create(PO_SCENE_UNLOAD_PHYS_LAYER, NIL));
  aMaster.ProcessObject(TProcessItem.create(PO_PATHS_UNLOAD, NIL));
  aMaster.ProcessObject(TProcessItem.create(PO_CONFIG_UNLOAD, NIL));
  aMaster.ProcessObject(TProcessItem.create(PO_TREE_CLEAR, nil));

  InsertPL.Enabled := False;
  InsertLL.Enabled := False;
  InsertPathsGroup.Enabled := False;
  InsertPath.Enabled := False;
  InsertPedestriansGroup.Enabled := False;
  InsertPedestrian.Enabled := False;
  InsertArrivalsGroup.Enabled := False;
  InsertArrival.Enabled := False;
  InsertRunProperties.Enabled := False;
  ProjectClose.Enabled := False;
  SaveConfig.Enabled := False;
  SimulationRun.Enabled := False;

  RemoveSelectedLayer.Enabled := False;
end;

procedure TfrmMain.Editor1Click(Sender: TObject);
begin
  frmEditor := TMainForm.Create(self);
  frmEditor.editor := aMaster.EditorManager;
  frmEditor.Show;
end;

procedure TfrmMain.ProjectNewAccept(Sender: TObject);
begin
  aMaster.ProcessObject(TProcessItem.create(PO_PROJECT_INSERT, TString.Create('Project 1')));
  aMaster.ProcessObject(TProcessItem.create(PO_TREE_SHOW_PROJECT, TString.Create('Project 1')));
  aMaster.ProcessObject(TProcessItem.create(PO_PROJECT_SAVE,
                      TString.Create(ProjectNew.Dialog.FileName)));

  InsertPL.Enabled := True;
  InsertPedestriansGroup.Enabled := True;
  InsertRunProperties.Enabled := True;
  ProjectClose.Enabled := True;
  SaveConfig.Enabled := True;

  RemoveSelectedLayer.Enabled := False;
end;

procedure TfrmMain.ProjectOpenAccept(Sender: TObject);
begin
  try
    aMaster.ProcessObject(TProcessItem.create(PO_PROJECT_LOAD,
    TString.Create(ProjectOpen.Dialog.FileName)));
    InsertPL.Enabled := True;
    InsertPedestriansGroup.Enabled := True;
    InsertRunProperties.Enabled := True;
    ProjectClose.Enabled := True;
    SaveConfig.Enabled := True;

    RemoveSelectedLayer.Enabled := False;
  except
    on e : Exception do
      ShowMessage('Error on project load!');
  end;
end;

procedure TfrmMain.RemoveSelectedLayerExecute(Sender: TObject);
begin
  aMaster.ProcessObject(TProcessItem.create(PO_TREE_REMOVE_SELECTED_LAYER, NIL))
end;

procedure TfrmMain.FormCreate(Sender: TObject);
begin
  aMaster := tMasterManager.create();
  aFormSimulation := TformSimulation.Create(nil);
  aFormSimulation.Simulation := nil;
  aSimulation := nil;
  aMaster.ProcessObject(TProcessItem.create(PO_TREE_SET_COMPONENT, TTreeViewProcesing.Create(treProject)));
end;

procedure TfrmMain.FormDestroy(Sender: TObject);
begin
  aMaster.Free;
  aFormSimulation.Free;
end;

procedure TfrmMain.InsertArrivalExecute(Sender: TObject);
var
  ret: TProcessItem;
begin
  ret := aMaster.ProcessObject(TProcessItem.create(PO_TREE_CAN_BE_CREATED_NEW_SUBARRIVAL, nil));
  if ret.Code = PO_SUCCESS then
    aMaster.ProcessObject(TProcessItem.create(PO_EDITOR_ARRIVAL_INSERT, NIL))
  else
    ShowMessage('musite oznacit skupinu prichodov');
end;

procedure TfrmMain.InsertArrivalsGroupExecute(Sender: TObject);
var
  frm: TfrmConfig;
  ret: TProcessItem;
begin
    frm := TfrmConfig.Create(nil);
    if frm.ShowModal('Arrivals Group') = 1 then
    begin
      ret := aMaster.ProcessObject(TProcessItem.create(PO_TREE_INSERT_ARRIVALS_LAYER, TString.Create(frm.getName)));
      if ret.Code <> PO_SUCCESS then
      begin
        aMaster.ProcessObject(TProcessItem.create(PO_PROJECT_INSERT_ARRIVALS_GROUP, TString.Create(frm.getName)));
      end
      else
        ShowMessage('Skupina prichodov s takymto nazvom uz existuje.');
    end;
    frm.Free;
end;

procedure TfrmMain.InsertLLExecute(Sender: TObject);
var
  ret: TProcessItem;
begin
  ret := aMaster.ProcessObject(TProcessItem.create(PO_TREE_CAN_BE_CREATED_NEW_LL, nil));
  if ret.Code = PO_SUCCESS then
    aMaster.ProcessObject(TProcessItem.create(PO_EDITOR_LL_NEW_FRM, nil))
  else
    ShowMessage('Najprv musite zaskrtnut fyzicku vrstvu');
end;

procedure TfrmMain.InsertPathExecute(Sender: TObject);
var
  ret: TProcessItem;
begin
  ret := aMaster.ProcessObject(TProcessItem.create(PO_TREE_CAN_BE_CREATED_NEW_SUBPATH, nil));
  if ret.Code = PO_SUCCESS then
    aMaster.ProcessObject(TProcessItem.create(PO_EDITOR_PATHS_NEW_FRM, nil))
  else
    ShowMessage('musite oznacit skupinu ciest');
end;

procedure TfrmMain.InsertPathsGroupExecute(Sender: TObject);
var
  frm: TfrmConfig;
  ret: TProcessItem;
begin
  ret := aMaster.ProcessObject(TProcessItem.create(PO_TREE_CAN_BE_CREATED_NEW_PATH, nil));
  if ret.Code = PO_SUCCESS then
  begin
    frm := TfrmConfig.Create(nil);
    if frm.ShowModal('Paths Group') = 1 then
    begin
      aMaster.ProcessObject(TProcessItem.create(PO_PATHS_UNLOAD, nil));
      ret := aMaster.ProcessObject(TProcessItem.create(PO_TREE_INSERT_PATHS_LAYER, TString.Create(frm.getName)));
      if ret.Code <> PO_SUCCESS then
      begin
        aMaster.ProcessObject(TProcessItem.create(PO_PROJECT_INSERT_PATHS, TString.Create(frm.getName)));
        aMaster.ProcessObject(TProcessItem.create(PO_PROJECT_SAVE_PATHS, nil))
      end
      else
        ShowMessage('Skupina ciest s takymto nazvom uz existuje.');
    end;
    frm.Free;
  end
  else
    ShowMessage('Najprv musite zaskrtnut logicku vrstvu');
end;

procedure TfrmMain.InsertPedestrianExecute(Sender: TObject);
var
  ret: TProcessItem;
begin
  ret := aMaster.ProcessObject(TProcessItem.create(PO_TREE_CAN_BE_CREATED_NEW_SUBPED, nil));
  if ret.Code = PO_SUCCESS then
    aMaster.ProcessObject(TProcessItem.create(PO_EDITOR_PED_INSERT, NIL))
  else
    ShowMessage('musite oznacit skupinu chodcov');
end;

procedure TfrmMain.InsertPedestriansGroupExecute(Sender: TObject);
var
  frm: TfrmConfig;
  ret: TProcessItem;
begin
    frm := TfrmConfig.Create(nil);
    if frm.ShowModal('Pedestrians Group') = 1 then
    begin
      aMaster.ProcessObject(TProcessItem.create(PO_PEDMAN_UNLOAD, nil));
      ret := aMaster.ProcessObject(TProcessItem.create(PO_TREE_INSERT_PEDEST_LAYER, TString.Create(frm.getName)));
      if ret.Code <> PO_SUCCESS then
      begin
        aMaster.ProcessObject(TProcessItem.create(PO_PROJECT_INSERT_PEDESTRIANS, TString.Create(frm.getName)));
        aMaster.ProcessObject(TProcessItem.create(PO_PROJECT_SAVE_PEDESTRIANS, nil))
      end
      else
        ShowMessage('Skupina chodcov s takymto nazvom uz existuje.');
    end;
    frm.Free;
end;

procedure TfrmMain.InsertPLExecute(Sender: TObject);
begin
  aMaster.ProcessObject(TProcessItem.create(PO_EDITOR_FL_NEW_FRM, nil));
end;

procedure TfrmMain.InsertRunPropertiesExecute(Sender: TObject);
begin
  aMaster.ProcessObject(TProcessItem.create(PO_RUNPROP_EDITOR_INSERT, NIL));
end;

procedure TfrmMain.ExitClick(Sender: TObject);
begin
  Application.Terminate;
end;

end.

